﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace timetableasy.Models
{
    public class StudyTimeRepository
    {
        private TimeTableDBDataContext db = new TimeTableDBDataContext();

        //Query Methods
        public IQueryable<StudyTime> FindAllStudyTimes()
        {
            return db.StudyTimes;
        }

        public StudyTime GetStudyTimeById(int id)
        {
            return db.StudyTimes.SingleOrDefault(st => st.StudyTimeId == id);
        }

        //Insert/Delete Methods

        public void Add(StudyTime studyTime)
        {
            db.StudyTimes.InsertOnSubmit(studyTime);
        }

        public void Delete(StudyTime studyTime)
        {
            db.StudyTimes.DeleteOnSubmit(studyTime);
        }

        //Persistence

        public void Save()
        {
            db.SubmitChanges();
        }
    }
}